/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CapaAccesoDatos;

import CapaDatos.Parametros;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

/**
 *
 * @author langeblanc
 */
public class ParametersDAO implements DAO {

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("marengoPU");
    EntityManager em = emf.createEntityManager();
    EntityTransaction et = em.getTransaction();

    public boolean create(Object obj) {
        boolean flag = true;
        Parametros ob = (Parametros) obj;
        et.begin();
        try {
            em.persist(ob);
            et.commit();
        } catch (Exception e) {
            et.rollback();
            flag = false;
        } finally {
            em.close();
        }
        return flag;
    }

    public boolean update(Object obj) {
        boolean flag = true;
        Parametros ob = (Parametros) obj;
        et.begin();
        try {
            em.merge(ob);
            et.commit();
        } catch (Exception e) {
            et.rollback();
            flag = false;
        } finally {
            em.close();
        }
        return flag;
    }

    public boolean delete(Object obj) {
        boolean flag = true;
        Parametros ob = (Parametros) obj;
        et.begin();
        try {
            em.remove(em.merge(ob));
            et.commit();
        } catch (Exception e) {
            et.rollback();
            flag = false;
        } finally {
            em.close();
        }
        return flag;
    }
}
